-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
updates to use context from the request for params instead of passing… #41
base: master
Are you sure you want to change the base?
Conversation
Awesome! |
} else { | ||
r.URL.RawQuery += q | ||
paramNames := []string{name} | ||
if v, ok := r.Context().Value("vestigo_param_names").([]string); ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not use a plain string type like that. See https://blog.golang.org/context#TOC_3.2.
if strings.HasPrefix(k, ":") { | ||
names = append(names, k) | ||
} | ||
if v, ok := r.Context().Value("vestigo_param_names").([]string); ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as below.
@@ -29,30 +30,34 @@ var AllowTrace = false | |||
|
|||
// Param - Get a url parameter by name | |||
func Param(r *http.Request, name string) string { | |||
return r.URL.Query().Get(":" + name) | |||
// use the request context | |||
if v, ok := r.Context().Value("vestigo_" + name).(string); ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as below.
} | ||
ctx := context.WithValue(r.Context(), "vestigo_"+name, value) | ||
ctx = context.WithValue(ctx, "vestigo_param_names", paramNames) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a better solution would be to store a map[string]string in the context with context.WithValue
and then use that to return the parameter, instead of using context.WithValue
for every single parameter. This would also prevent multiple lists from being stored. Above, for every URL parameter, a new context with the slice paramNames and key "vestigo_param_names"
is linked with the others. It would also let you have a single package level key to access the map and prevent collisions. See https://github.com/pressly/chi/blob/master/context.go#L50 for an example.
When will this be merged to master? |
This has been on Ice for a bit. I will take a look at this this week. I want to make sure it doesn't break anything before merging.
…On May 16, 2017 10:58:19 AM EDT, Calle Gustafsson ***@***.***> wrote:
When will this be merged to master?
--
You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub:
#41 (comment)
|
+1 for interest in seeing this merged |
… them in the url